import math
import time

from pywinauto import mouse, Application

# mouse.click(coords=(666,666))
# time.sleep(3)
# mouse.click(coords=(999,999))

# mouse.double_click(coords=(260,17))

# mouse.right_click(coords=(260,17))

#大于0：向上滚动
#小于0：向下滚动
# mouse.scroll(coords=(900,600),wheel_dist=-10)

app=Application(backend="uia").connect(process=19652)
win=app.window(title_re=".*Sublime Text.*")
win.wait("exists")

# win.print_control_identifiers()

proc=win.child_window(title="应用程序", auto_id="MenuBar", control_type="MenuBar")
rect=proc.rectangle()
# print(rect)
#
# width=rect.right-rect.left
# height=rect.bottom-rect.top
# print(f"{width}---{height}")
#
# width=math.floor(width/2)+rect.left
# height=math.floor(height/2)+rect.top
# mouse.move(coords=(width,height))

# mid_point=rect.mid_point()
# mouse.move(coords=(mid_point.x,mid_point.y))

for i in proc.children():
    point=i.rectangle().mid_point()
    # #计算控件的中间位置
    # width=rect.right-rect.left
    # height=rect.bottom-rect.top

    mouse.click(coords=(point.x,point.y))
    time.sleep(1)
    mouse.click(coords=(point.x,point.y))
    time.sleep(1)